class Solution(object):
    def intersectionSizeTwo(self, intervals):
        intervals.sort()
        now_min = [float('inf'), float('inf')]
        n = len(intervals)
        ans = 0
        print(intervals)
        for i in range(n - 1, -1, -1):
            if intervals[i][1] >= now_min[-1]:
                continue
            else:
                if intervals[i][1] >= now_min[0]:
                    ans += 1
                    if now_min[0] == intervals[i][0]:
                        now_min = [intervals[i][0], intervals[i][0] + 1]
                    else:
                        now_min = [intervals[i][0], now_min[0]]
                else:
                    ans += 2
                    now_min[0] = intervals[i][0]
                    now_min[1] = intervals[i][0] + 1
        return ans


data = Solution()
intervals = [[0, 1], [0, 3], [0, 2], [3, 4], [2, 5]]
print(data.intersectionSizeTwo(intervals))
